﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using My3DGame.Game_Base.Cameras;

namespace My3DGame.Game_States
{
    class clsHelpState : clsStateGame
    {
        KeyboardState oldKeyboardState;
        List<Texture2D> lstImages= new List<Texture2D>();
        Vector2 pos = new Vector2(0, 0);
        // Model stuff
        clsMenuModelManager clsMenuModelManager;

        // Camera
        public clsCameraBackground camera { get; protected set; }

        // Random
        public Random rand { get; protected set; }

        public clsHelpState(Game1 game1)
        {
            nextGameState = clsStateGameManager.StateGame.MENU;
        }

        public override void Initialize(Game1 game1)
        {
            // Initialize Camera
            camera = new clsCameraBackground(this, new Vector3(0, 0, 50), Vector3.Zero, Vector3.Up);
            Components.Add(camera);

            clsMenuModelManager = new clsMenuModelManager(this, camera, game1);
            base.Initialize(game1);
        }

        public override void LoadContent(Game1 game1)
        {
            lstImages.Add(game1.Content.Load<Texture2D>(@"2DImages\Help\Help"));
            base.LoadContent(game1);
        }

        public override void Update(GameTime gameTime, Game1 game1)
        {
            pos.X = game1.Window.ClientBounds.Width/2 - lstImages[0].Width/2;
            pos.Y = game1.Window.ClientBounds.Height / 2 - lstImages[0].Height / 2;

            clsMenuModelManager.Update(gameTime);
            HandleInput(game1);

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime, Game1 game1)
        {
            clsMenuModelManager.Draw(gameTime);

            game1.spriteBatch.Begin();

            // Vẽ about giữa màn hình.
            game1.spriteBatch.Draw(lstImages[0], pos, Color.White);


            game1.spriteBatch.End();

            base.Draw(gameTime, game1);
        }
    
        private void HandleInput(Game1 game1)
        {
            #region Xử lý menu với bàn phím.

            KeyboardState keyboard = Keyboard.GetState();
            if (oldKeyboardState != keyboard)
            {
                if (keyboard.IsKeyDown(Keys.Escape))
                {
                    nextGameState = clsStateGameManager.StateGame.MENU;
                    game1.stateGameManager.NextState(game1);
                }
            }
            oldKeyboardState = keyboard;

            #endregion
        }
    }
}
